	<%@page import="com.situ.student.entity.PageBean"%>
	<%@page import="com.situ.student.entity.Student"%>
	<%@page import="java.util.List"%>
	<%@page import="com.situ.student.service.impl.StudentServiceImpl"%>
	<%@page import="com.situ.student.service.IStudentService"%>
	<%@ page language="java" contentType="text/html; charset=UTF-8"
	    pageEncoding="UTF-8"%>
	<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>   
	<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
	<html>
	<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
	<title>Insert title here</title>
	<link rel="stylesheet" type="text/css" href="lib/bootstrap-3.3.7-dist/css/bootstrap.css"/>
	<style type="text/css">
		.align-center{
		    width: 800px;
			margin : 10px auto;
		}
		table{
			table-layout : fixed;
			word-break : break-all;
		}
	</style>
	</head>
	<body>
	
	<!-- jsp脚本、输出替换为El和Jstl -->
	
		<%-- <%
			PageBean pageBean = (PageBean)request.getAttribute("pageBean");
		%> --%>
		${requstScope.pageBean}
		
		<div class="align-center">
				
				<%-- 获取绝对路径${pageContext.request.contextPath}
					等同于<%request.getContentType()%> --%>
				欢迎登陆：${user.name}
				<a href="${pageContext.request.contextPath}/user?method=logout">注销</a><br/>
				<a href="student_add.jsp">添加</a>
				<a href="javascript:deleteAll()">批量删除</a>
				<form action="${pageContext.request.contextPath}/student?method=pageList" method="post"></form>
				姓名：<input type="text" name="name"/>
				<input type="submit" value="搜索"/>
				
				
				<form action="" id="mainForm" method="post">
				<!-- 遍历List<Student> list -->
					<table class="table table-striped table-bordered table-hover table-condensed">
						<tr>
						<td><input type="checkbox" id="selectAlls" onclick="selectAll()"/></td>
						<td>ID</td>
						<td>姓名</td>
						<td>年龄</td>
						<td>性别</td>
						<td>修改</td>
						<td>删除</td>
						</tr>
								
						<c:forEach items="${pageBean.list}" var="student">
							<tr>
								<td><input type="checkbox" name="selectIds" value="${student.id}"/></td>
								<td>${student.id}</td>
								<td>${student.name}</td>
								<td>${student.age}</td>
								<td>${student.gender}</td>
								<td><a href="${pageContext.request.contextPath}/student?method=toUpdate&id=${student.id}">修改</a></td>
								<td><a href="javascript:deleteById(${student.id})">删除</a></td>
							</tr>
							</c:forEach>
					</table>
				</form>
			</table>
			
			
			
			<nav aria-label="Page navigation">
			  <ul class="pagination">
			   	 
			   	 	 <!-- 上一页 开始 -->
			  		<!--  如果当前已经是第一页，就不能点击上一页 -->
			     
			      <c:if test="${pageBean.pageNo == 1 }">
			      	  <li class="disabled">
			      		<a  href="#" aria-label="Previous">
				       		<span aria-hidden="true">&laquo;</span>
				   		</a>
				   	  </li>
			      </c:if>
			      <c:if test="${pageBean.pageNo != 1 }">
			      	  <li >
					      <a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${pageBean.pageNo - 1}&pageSize=3" aria-label="Previous">
					      	<span aria-hidden="true">&laquo;</span>
					      </a>
					  </li>
			      </c:if>
			       <!-- 上一页 结束 -->
			       
			       <!-- 变量为i，初始为1，结束为最大页数 -->
			    	<c:forEach var="i" begin="1" end="${pageBean.totalPage}">
			   	 	<c:if test="${i == pageBean.pageNo }">
						<li class="active"><a href="#">${i}</a></li>
			    	</c:if>
			    	<c:if test="${i != pageBean.pageNo}">
						<li><a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${i}&pageSize=3">${i}</a></li>
			    	</c:if>
			    	</c:forEach>
			    
			    
			     <!-- 下一页 开始 -->
			    	<c:if test="${pageBean.pageNo == pageBean.totalPage}">
			    		 <li class="disabled">
			      			<a  href="#" aria-label="Previous">
				        		<span aria-hidden="true">&raquo;</span>
				   			</a>
				   	  	</li>
			   		 </c:if>
			     	<c:if test="${pageBean.pageNo != pageBean.totalPage}">
			    	 	<li >
				      		<a href="${pageContext.request.contextPath}/student?method=pageList&pageNo=${pageBean.pageNo + 1}&pageSize=3" aria-label="Previous">
				        		<span aria-hidden="true">&raquo;</span>
				      		</a>
				  		</li>
			     	</c:if>
			     <!-- 下一页 结束 -->
			  </ul>
			</nav>
		</div>
		
		<!--bootstrap.js用到了jquery，所以要首先引入jquery -->
		<script type="text/javascript" src="lib/jquery/jquery-1.11.1.js" ></script>
		<script type="text/javascript" src="lib/bootstrap-3.3.7-dist/js/bootstrap.js" ></script>
		<script type="text/javascript">
			function deleteById(id) {
				//用户点了确定，confirm返回的是true，
				//用户点了取消，confirm返回的是false，
				var isDel = confirm("您确认要删除么？");
				if (isDel) {
					location.href = "${pageContext.request.contextPath}/student?method=deleteById&id=" + id;
				} 
			}
			
				function selectAll(){   
				//得到上面全选、反选按钮的状态
				var isChecked = $("#selectAlls").prop("checked");
				//下面所有checkbox的状态和上面全选、反选checkbox的状态一致
				$("input[name=selectIds]").prop("checked", isChecked);
				}	
				
				function deleteAll(){
					$("#mainForm").attr("action", "${pageContext.request.contextPath}/student?method=deleteAll");
					//用代码方式提交表单
					$("#mainForm").submit();
					//提示
					var isDels = confirm("您确认要删除么？");
					if (isDels) {
						location.href = "${pageContext.request.contextPath}/student?method=pageList" + all ;
					} 
				}
		</script>
	</body>
	</html>